/*
 * @Descripttion:
 * @Author: Wang Dejiang(aei)
 * @Date: 2022-08-02 21:25:17
 * @LastEditors: Wang Dejiang(aei)
 * @LastEditTime: 2022-08-03 21:51:09
 */
import { io } from "socket.io-client";
// 线上
// const socket = io("http://120.78.137.246:9999", {
//   transports: ["websocket"],
// });
const socket = io(
  "http://koa.monitor-server-koa.1582182718458392.cn-hangzhou.fc.devsapp.net",
  {
    transports: ["websocket"],
  }
);

// 本地
// const socket = io("http://localhost:9999", {
// 	transports: ["websocket"]
// });

// socket.on.error

// 初始化 自己
export const IOINIT = () => {
  socket.emit("init");
};

// 发送信息
export const sendMsgIO = (val) => {
  socket.emit("sendMsg", val);
};
// 保存ID
export const saveIDIO = () => {
  return new Promise((resolve) => {
    socket.on("save-id", (val) => resolve(val));
  });
};
// 接收信息
export const receiveMsgIO = () => {
  return new Promise((resolve) => {
    socket.on("receiveMess", (val) => {
      console.log("所有聊天室");
      resolve(val);
    });
  });
};

export default socket;
